/*
 * 文件名：LocalRotaServiceImpl.java	 
 * 时     间：下午3:36:32
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.common.CommonContains;
import com.local.dao.mapers.LocalBlackListMapper;
import com.local.dao.mapers.LocalCarInRepertoryMapper;
import com.local.model.LocalBlackList;
import com.local.model.LocalBlackListExample;
import com.local.model.LocalCarInRepertory;
import com.local.model.LocalCarInRepertoryExample;
import com.local.page.LocalBlackListPage;
import com.local.service.face.LocalBlackListService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.Tools;
import com.qianhai.common.utils.UUIDGenerateUtil;

/** 
 * 类描述:这里是类描述
 * @ClassName: LocalRotaServiceImpl 
 * @author Administrator
 * @date 2015年10月3日 下午3:36:32 
 */
@Service
public class LocalBlackListServiceImpl extends
BaseServiceImpl<LocalBlackListExample, LocalBlackList, String> implements LocalBlackListService
{
	@Autowired
	private LocalBlackListMapper localBlackListMapper;
	
	@Autowired
	private LocalCarInRepertoryMapper localCarInRepertoryMapper;

	@Override
	public BaseMapper<LocalBlackListExample, LocalBlackList, String> getMapper()
	{
		// TODO Auto-generated method stub
		return localBlackListMapper;
	}

	@Override
	public List<LocalBlackList> queryBlackListByPage(LocalBlackListPage<LocalBlackList> page)
	{
		// TODO Auto-generated method stub
		Integer recordCount = localBlackListMapper.countAllByPage(page);
		page.setTotalRecords(recordCount);
		List<LocalBlackList> list = localBlackListMapper.queryByPage(page);
		page.setData(list);
		return list;
	}

	@Override
	public String saveOrUpdateLocalBlackList(LocalBlackList localBlackList)
	{
		// TODO Auto-generated method stub
		try
		{
			if (Tools.isEmpty(localBlackList.getUuid()))
			{
				localBlackList.setUuid(UUIDGenerateUtil.generate());
				localBlackListMapper.insert(localBlackList);
			} else
			{
				localBlackListMapper.updateByPrimaryKey(localBlackList);
			}
			//LocalCarInRepertory carInRepertory = localCarInRepertoryMapper.queryCarInRepertoryByCarNo(localBlackList.getCarNo());
			LocalCarInRepertoryExample carInEx = new LocalCarInRepertoryExample();
			carInEx.or().andCarNoEqualTo(localBlackList.getCarNo().trim());
			List<LocalCarInRepertory> localCarInRepertories = localCarInRepertoryMapper.selectByCondition(carInEx);
			if (!Tools.isEmpty(localCarInRepertories)) {
			for (LocalCarInRepertory carInRepertory : localCarInRepertories) {
				if (CommonContains.BLACK_LIST.equals(localBlackList.getType())) {
					carInRepertory.setOpenType(CommonContains.OPEN_TYPE_BLACK);
					carInRepertory.setPayType(CommonContains.BLACK_LIST);
				} else if (CommonContains.WHITE_LIST.equals(localBlackList.getType())) {
					carInRepertory.setOpenType(CommonContains.OPEN_TYPE_TRUE);
					carInRepertory.setPayType(CommonContains.WHITE_LIST);
				}
				carInRepertory.setExpireTime(localBlackList.getEndTime());
				localCarInRepertoryMapper.updateByPrimaryKeySelective(carInRepertory);
			}
			}
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
		return localBlackList.getUuid();
	}

	@Override
	public LocalBlackList queryBlackListByCarNo(String carNo)
	{
		// TODO Auto-generated method stub
		LocalBlackList lc=localBlackListMapper.queryBlackListByCarNo(carNo);
		return lc;
	}

	@Override
	public void deleteBlackListCarNo(LocalBlackList localBlackList)
	{
		// TODO Auto-generated method stub
		LocalBlackListExample condition=new LocalBlackListExample();
		condition.or().andCarNoEqualTo(localBlackList.getCarNo());
		localBlackListMapper.deleteByCondition(condition);
	}
	
}
